
import random
from fractions import Fraction
def random_pick(some_list, probabilities):
    result = (  )
    for i in range(0, 2):
        cumulative_probability = 0.0
        x = random.uniform(0, 1)
        for item, item_probability in zip(some_list, probabilities):
            cumulative_probability += item_probability
            if x < cumulative_probability:
                result += (item,)
                break
    return result

def random_filter(num):
    a = [1, 0]
    b = [Fraction(1, 3), Fraction(2, 3)]
    all_collection = [(0, 1), (1, 0), (0, 0), (1, 1)]
    result_collection = [(0, 1), (1, 0)]
    all, re, count = dict(zip(all_collection, [0] * 4)), dict \
        (zip(result_collection, [0] * 2)), 0
    for x in range(num):
        result = random_pick(a, b)
        all[result] += 1
        if result in result_collection:
            count += 1
            re[result] += 1
    for v, value in re.items():
        re[v] = float(value ) /count
    for v, value in all.items():
        all[v] = float(value ) /num
    return all, re

for item in random_filter(100000):
    print(item)